﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ePrice.Models;

namespace ePrice.Controllers
{
    public partial class AdminController
    {
        //
        // GET:
        public ActionResult ProductManager(string act, string pid)
        {
            if (String.IsNullOrEmpty(act)) act = "Search";
            switch (act.ToLower())
            {
                case "create":
                    {
                        ViewBag.Action = "Create";
                        return View();
                    }
                case "edit":
                    {
                        int id = Convert.ToInt32(pid);
                        ViewBag.Action = "Edit";
                        Product product = db.Products.Find(id);
                        return View(product);
                    }
                case "delete":
                    {
                        int id = Convert.ToInt32(pid); // Exeption may be raised
                        ViewBag.Action = "Delete";
                        Product product = db.Products.Find(id);
                        return View(product);
                    }
                case "search":
                    {
                        ViewBag.Action = "Search";
                        return View();
                    }
                case "list":
                    {
                        ViewBag.Action = "List";
                        List<Product> list = new List<Product>();
                        list = db.Products.ToList();
                        ViewBag.List = list;
                        break;
                    }
                default:
                    {
                        ViewBag.Action = "Search";
                        return View();
                    }
            }
            return View();
        }

        //
        // POST:
        [HttpPost]
        public ActionResult ProductManager(string act, string pid, Product product)
        {
            if (String.IsNullOrEmpty(act)) act = "Search";
            switch (act.ToLower())
            {
                case "create":
                    {
                        if (ModelState.IsValid)
                        {
                            db.Products.Add(product);
                            db.SaveChanges();
                            return RedirectToAction("Index");
                        }
                        return View(product);
                    }
                case "edit":
                    {
                        ViewBag.Action = "Edit";
                        break;
                    }
                case "delete":
                    {
                        ViewBag.Action = "Delete";
                        break;
                    }
                case "search":
                    {
                        ViewBag.Action = "Search";
                        break;
                    }
                case "list":
                    {
                        ViewBag.Action = "List";
                        break;
                    }
                default:
                    {
                        ViewBag.Action = "Seacrh";
                        break;
                    }
            }
            return View();
        }


        public void createProduct(HttpVerbs verb)
        {
            switch (verb)
            {
                case HttpVerbs.Get:
                    {
                        break;
                    }
                case HttpVerbs.Post:
                    {
                        break;
                    }
            }
        }

        public void editProduct(string pid, HttpVerbs verb)
        {

        }

        public void deleteProduct(string pid, HttpVerbs verb)
        {

        }

        public void searchProduct(string name, HttpVerbs verb)
        {
        }

        public void listProduct(HttpVerbs verb)
        {
        }
    }
}